package com.patni.body;



import java.awt.Color;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;

import com.patni.frame.util.MoveThread;
import com.patni.frame.util.MyScrollPane;

public class Body extends JLabel{

/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	

JLabel bodyTitle;

public static JLabel bodyContentpane;

public static MyScrollPane msp;

public static BodyListDetail detail;

int titleHeight=34;
int iconWidth=14;
int wid;
int hei;
JPanel p1;
JPanel p2;
JPanel p3;
JPanel p4;
JLabel iconLabel[];
Icon labelImage[];
private static int temp=0;
private int temp1=-1;

public Body(int wid,int hei){
	
	this.wid=wid;
	this.hei=hei;
	this.setSize(wid,hei);

	this.setLayout(null);
	this.setBorder(BorderFactory.createMatteBorder(0, 1, 0, 1, new Color(116,202,230)));
	
	bodyTitle=new JLabel();
	bodyTitle.setLayout(null);
	
	bodyContentpane=new JLabel();
	bodyContentpane.setLayout(null);
	
	bodyContentpane.setLocation(0,0);
	
	detail=new BodyListDetail();

	p1=new JPanel();
	p2=new JPanel();
	p3=new JPanel();
	p4=new JPanel();
	p1.setLayout(null);
	p2.setLayout(null);
	p3.setLayout(null);
	p4.setLayout(null);
	
	labelImage=new ImageIcon[8];
	for(int i=0;i<8;i++){
		int a=i/2+1;
		int b=2;
		if(i%2==0)
		b=1;	
		labelImage[i]=new ImageIcon("bodyImage/"+a+b+".png");
	}
	
	iconLabel=new JLabel[8];
	for(int i=0;i<8;i++){
		iconLabel[i]=new JLabel();
		iconLabel[i].setSize(iconWidth*2,titleHeight);
		iconLabel[i].setIcon(labelImage[i]);
	}
	
	titleChange();
	bodyContentpaneChange();
	
	msp=new MyScrollPane(bodyContentpane);
	msp.setLocation(0, titleHeight);
	mspChangeSize();
	
	this.add(bodyTitle);
	this.add(msp);
	

	
	p1.addMouseListener(new MouseListener(){

		@Override
		public void mouseClicked(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void mouseEntered(MouseEvent e) {
			// TODO Auto-generated method stub
			if(temp!=0){
			temp1=0;
			titleIconChange();
			}
		}

		@Override
		public void mouseExited(MouseEvent e) {
			// TODO Auto-generated method stub
			if(temp!=0){
			temp1=-1;
			titleIconChange();
			}
		}

		@Override
		public void mousePressed(MouseEvent e) {
			// TODO Auto-generated method stub
			if(temp!=0){
				temp=0;
				temp1=-1;
				titleIconChange();
				bodyContentpaneChange();
			}
		}

		@Override
		public void mouseReleased(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}
		
	});
	p2.addMouseListener(new MouseListener(){

		@Override
		public void mouseClicked(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void mouseEntered(MouseEvent e) {
			// TODO Auto-generated method stub
			if(temp!=1){
			temp1=1;
			titleIconChange();
			}
		}

		@Override
		public void mouseExited(MouseEvent e) {
			// TODO Auto-generated method stub
			if(temp!=1){
			temp1=-1;
			titleIconChange();
			}
		}

		@Override
		public void mousePressed(MouseEvent e) {
			// TODO Auto-generated method stub
			if(temp!=1){
				temp=1;
				temp1=-1;
				titleIconChange();
				bodyContentpaneChange();
			}
		}

		@Override
		public void mouseReleased(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}
		
	});
	p3.addMouseListener(new MouseListener(){

		@Override
		public void mouseClicked(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void mouseEntered(MouseEvent e) {
			// TODO Auto-generated method stub
			if(temp!=2){
			temp1=2;
			titleIconChange();
			}
		}

		@Override
		public void mouseExited(MouseEvent e) {
			// TODO Auto-generated method stub
			if(temp!=2){
			temp1=-1;
			titleIconChange();
			}
		}

		@Override
		public void mousePressed(MouseEvent e) {
			// TODO Auto-generated method stub
			if(temp!=2){
				temp=2;
				temp1=-1;
				titleIconChange();
				bodyContentpaneChange();
			}
		}

		@Override
		public void mouseReleased(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}
		
	});
	p4.addMouseListener(new MouseListener(){

		@Override
		public void mouseClicked(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}

		@Override
		public void mouseEntered(MouseEvent e) {
			// TODO Auto-generated method stub
			if(temp!=3){
			temp1=3;
			titleIconChange();
			}
		}

		@Override
		public void mouseExited(MouseEvent e) {
			// TODO Auto-generated method stub
			if(temp!=3){
			temp1=-1;
			titleIconChange();
			}
		}

		@Override
		public void mousePressed(MouseEvent e) {
			// TODO Auto-generated method stub
			if(temp!=3){
				temp=3;
				temp1=-1;
				titleIconChange();
				bodyContentpaneChange();
			}
		}

		@Override
		public void mouseReleased(MouseEvent e) {
			// TODO Auto-generated method stub
			
		}
		
	});
}
public void changeSize(int wid,int hei){
	this.wid=wid;
	this.hei=hei;
	this.setSize(wid,hei);
	TitleSizeChange();
	mspChangeSize();
}

public void titleChange(){
	TitleSizeChange();
	titleIconChange();
	bodyTitle.add(p1);
	bodyTitle.add(p2);
	bodyTitle.add(p3);
	bodyTitle.add(p4);
}
public void TitleSizeChange(){

//	this.setSize(wid, hei);

	for(int i=0;i<8;i++){
		iconLabel[i].setLocation(wid/8-iconWidth, 0);
	}

	p1.setBounds(0, 0, wid/4, titleHeight);
	p2.setBounds(wid/4,0, wid/4, titleHeight);
	p3.setBounds(wid/4*2,0, wid/4, titleHeight);
	p4.setBounds(wid/4*3,0,wid- 3*(wid/4), titleHeight);
	bodyTitle.setBounds(0, 0, wid, titleHeight);
	
}
public void titleIconChange(){
	p1.setBackground(new Color(185,217,232));
	p2.setBackground(new Color(185,217,232));
	p3.setBackground(new Color(185,217,232));
	p4.setBackground(new Color(185,217,232));
	
	p1.removeAll();
	p2.removeAll();
	p3.removeAll();
	p4.removeAll();
	p1.add(iconLabel[0]);
	p2.add(iconLabel[2]);
	p3.add(iconLabel[4]);
	p4.add(iconLabel[6]);
	
	
	switch(temp){
	case 0:p1.setBackground(new Color(225,242,249));p1.removeAll();p1.add(iconLabel[1]);break;
	case 1:p2.setBackground(new Color(225,242,249));p2.removeAll();p2.add(iconLabel[3]);break;
	case 2:p3.setBackground(new Color(225,242,249));p3.removeAll();p3.add(iconLabel[5]);break;
	case 3:p4.setBackground(new Color(225,242,249));p4.removeAll();p4.add(iconLabel[7]);break;
	default:break;
	}
	
	switch(temp1){
	case 0:p1.setBackground(new Color(210,234,246));break;
	case 1:p2.setBackground(new Color(210,234,246));break;
	case 2:p3.setBackground(new Color(210,234,246));break;
	case 3:p4.setBackground(new Color(210,234,246));break;
	default:break;
	}
}

public static void bodyContentpaneChange(){
	bodyContentpane.removeAll();
	bodyContentpane.add(detail.bodyListDetail[0]);
	bodyContentpane.add(detail.bodyListDetail[1]);
	bodyContentpane.add(detail.bodyListDetail[2]);
	bodyContentpane.add(detail.bodyListDetail[3]);
	int width=detail.width; 
	int height=0;
	int type=0;
	switch(temp){
	case 0:height=detail.bodyListDetail[0].getHeight();type=0;break;
	case 1:height=detail.bodyListDetail[1].getHeight();type=1;break;
	case 2:height=detail.bodyListDetail[2].getHeight();type=2;break;
	case 3:height=detail.bodyListDetail[3].getHeight();type=3;break;
	default:break;
	}

	int x1=bodyContentpane.getX();
	int x2=-type*width;
	
//	bodyContentpane.setSize(width*4, height);
	setBodyHeight(width, height);

	Thread t =new Thread(new MoveThread(bodyContentpane,x1,x2));
	t.start();
}

public static void setBodyHeight(int width,int height){
	bodyContentpane.setSize(width*4, height);
}

public void mspChangeSize(){
	msp.setSize(wid,hei-titleHeight);
}



}
